﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;
using System.Collections.ObjectModel;

namespace University.Workshop.Presenters.WaterPurchase
{
    public class PresenterSearchWaterPurchase
    {
        ISearchWaterPurchaseView view;

        public PresenterSearchWaterPurchase(ISearchWaterPurchaseView view)
        {
            this.view = view;
        }

        public void SearchWaterPurchase()
        {
            bool entra = true;
            try
            {
                Model.WaterPurchase u = new Model.WaterPurchase() { LicencePlate = view.LicencePlate};
                
                //if ( view.Courtesy 

                try
                {
                    u.DatePurchase = view.DatePurchase;
                }
                catch (Exception ex)
                {
                    entra = false;
                }
                if (entra)
                    view.WaterPurchaseFinded = ManagerWaterPurchase.SearchWaterPurchaseByParameter(u, view.Courtesy);
                else
                    view.WaterPurchaseFinded = ManagerWaterPurchase.SearchWaterPurchaseMinusDate(u, view.Courtesy);

            }
            catch (Exception ex)
            {
                view.WaterPurchaseFinded = null;
                view.NotifyErrorMessage(ex.Message);
            }
        }



        public void ShowDisableUser()
        {
            view.OpenDisableUserPopUp(ManagerWaterPurchase.GetWaterPurchaseByLicencePlate(view.WaterPurchaseSelected));
            WaterPurchaseForDisable = view.WaterPurchaseSelected;

        }

        /*public void ShowEnableUser()
        {
            if (view.NotifyConfirmationMessage("¿Está seguro que desea habilitar al usuario?"))
            {
                view.OpenDisableUserPopUp(ManagerUser.GetUserByUserId(view.UserSelected));
                WaterPurchaseForDisable = view.UserSelected;
            }
        }

        public void EnableUser()
        {
            if (view.NotifyConfirmationMessage("Confirmacón de habilitación de usuario"))
            {
                ManagerUser.EnableUser(WaterPurchaseForDisable);
                view.NotifySystemMessage("El usuario fue habilitado exitosamente");
                WaterPurchaseForDisable = null;
                HideDisableUser();
                CleanSearch();
            }
        }

        public void DisableUser()
        {
            if (view.NotifyConfirmationMessage("Confirmacón de inhabilitación de usuario"))
            {
                ManagerUser.DisableUser(WaterPurchaseForDisable);
                view.NotifySystemMessage("El usuario fue deshabilitado exitosamente");
                WaterPurchaseForDisable = null;
                HideDisableUser();
                CleanSearch();
            }
        }*/

        public void HideDisableUser()
        {
            view.HideDisableUser();
        }

        private void CleanSearch()
        {
            view.LicencePlate = string.Empty;
            view.WaterPurchaseFinded = new Collection<Model.WaterPurchase>();
            //view.DatePurchase = null;
            //view.Courtesy = string.Empty;
        }

        public Model.WaterPurchase WaterPurchaseForDisable { get; set; }

        /*public void ModifyUser()
        {
            view.GoToModifyUser(ManagerUser.GetUserByUserId(view.UserSelected));
        }*/

    }
}
